home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Enigma Amiga CD / Listati / 63-Marzo-esempio.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  5KB  |  217 lines

  1. /*
  2.  
  3.            Esempio di generazione primitive grafiche elementari
  4.           Realizzato da Silvio Umberto Zanzi per EnigmA Amiga Run
  5.  
  6.  *  Source machine generated by GadToolsBox V2.0b
  7.  *  which is (c) Copyright 1991-1993 Jaba Development
  8.  *
  9.  *  GUI Designed by : -- Unnamed --
  10.  
  11. Quanto segue, fino al blocco main(), è stato realizzato  in modo automatico
  12. per mezzo del costrutture di interfacce utente GadToolsBox.
  13. Al sorgente originale sono state eseguite solo marginali modifche al fine
  14. di migliorare la leggibilità.
  15.  
  16. Nota:
  17. Vengono usate le metodologie di programmazione introdotte dalla versione
  18. 2.x del sistema operativo.
  19.  
  20. */
  21.  
  22. #include <exec/types.h>
  23. #include <intuition/intuition.h>
  24. #include <intuition/classes.h>
  25. #include <intuition/classusr.h>
  26. #include <intuition/imageclass.h>
  27. #include <intuition/gadgetclass.h>
  28. #include <libraries/gadtools.h>
  29. #include <graphics/displayinfo.h>
  30. #include <graphics/gfxbase.h>
  31. #include <graphics/gfxmacros.h>
  32. #include <clib/exec_protos.h>
  33. #include <clib/intuition_protos.h>
  34. #include <clib/gadtools_protos.h>
  35. #include <clib/graphics_protos.h>
  36. #include <clib/utility_protos.h>
  37. #include <clib/dos_protos.h>
  38. #include <string.h>
  39.  
  40. #include "esempio.h"
  41.  
  42. struct Screen         *Scr = NULL;
  43. APTR                   VisualInfo = NULL;
  44. struct Window         *Finestra_di_lavoroWnd = NULL;
  45. UWORD                  Finestra_di_lavoroLeft = 0;
  46. UWORD                  Finestra_di_lavoroTop = 12;
  47. UWORD                  Finestra_di_lavoroWidth = 640;
  48. UWORD                  Finestra_di_lavoroHeight = 233;
  49. UBYTE                 *Finestra_di_lavoroWdt = (UBYTE *)"Finestra di lavoro";
  50.  
  51. struct TextAttr topaz8 = {
  52.     ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
  53.  
  54.  
  55. UWORD DriPens[] = {
  56.     (unsigned short)~0 };
  57.  
  58. int SetupScreen( void )
  59. {
  60.     if ( ! ( Scr = OpenScreenTags( NULL, SA_Left,    0,
  61.                     SA_Top,        0,
  62.                     SA_Width,    640,
  63.                     SA_Height,    256,
  64.                     SA_Depth,    2,
  65.                     SA_Font,    &topaz8,
  66.                     SA_Type,    CUSTOMSCREEN,
  67.                     SA_DisplayID,    PAL_MONITOR_ID|HIRES_KEY,
  68.                     SA_Pens,    &DriPens[0],
  69.                     SA_Title,    "EnigmA Amiga Run - esempio primitive grafiche elememtari",
  70.                     TAG_DONE )))
  71.         return( 1L );
  72.  
  73.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  74.         return( 2L );
  75.  
  76.     return( 0L );
  77. }
  78.  
  79. void CloseDownScreen( void )
  80. {
  81.     if ( VisualInfo ) {
  82.         FreeVisualInfo( VisualInfo );
  83.         VisualInfo = NULL;
  84.     }
  85.  
  86.     if ( Scr        ) {
  87.         CloseScreen( Scr );
  88.         Scr = NULL;
  89.     }
  90. }
  91.  
  92. int OpenFinestra_di_lavoroWindow( void )
  93. {
  94.     UWORD        offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  95.  
  96.     if ( ! ( Finestra_di_lavoroWnd = OpenWindowTags( NULL,
  97.                 WA_Left,    Finestra_di_lavoroLeft,
  98.                 WA_Top,        Finestra_di_lavoroTop,
  99.                 WA_Width,    Finestra_di_lavoroWidth,
  100.                 WA_Height,    Finestra_di_lavoroHeight + offy,
  101.                 WA_IDCMP,    IDCMP_REFRESHWINDOW,
  102.                 WA_Flags,    WFLG_DRAGBAR|WFLG_SMART_REFRESH|WFLG_GIMMEZEROZERO|WFLG_ACTIVATE|WFLG_RMBTRAP,
  103.                 WA_Title,    Finestra_di_lavoroWdt,
  104.                 WA_ScreenTitle,    "Enigma Amiga Run - esempio primitive grafiche elementari",
  105.                 WA_CustomScreen,    Scr,
  106.                 TAG_DONE )))
  107.     return( 4L );
  108.  
  109.     GT_RefreshWindow( Finestra_di_lavoroWnd, NULL );
  110.  
  111.     return( 0L );
  112. }
  113.  
  114. void CloseFinestra_di_lavoroWindow( void )
  115. {
  116.     if ( Finestra_di_lavoroWnd        ) {
  117.         CloseWindow( Finestra_di_lavoroWnd );
  118.         Finestra_di_lavoroWnd = NULL;
  119.     }
  120. }
  121.  
  122. /*
  123.  /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  124. (    Fine codice GadToolsBox                                                 )
  125.  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  126. */
  127.  
  128. void fine(void); /* prototipo per funzione di uscita */
  129.  
  130. struct IntuitionBase    *IntuitionBase;
  131. struct GfxBase        *GfxBase;
  132. struct RastPort         *RastPort;
  133.  
  134. void main(void)
  135. {
  136. short cont;
  137.  
  138. /*
  139.  /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  140. (    Apertura librerie e impostazione schermo e finestre                     )
  141.  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  142. */
  143.  
  144. IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",36);
  145. if (!IntuitionBase) fine();
  146.  
  147. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",36);
  148. if (!GfxBase) fine();
  149.  
  150. SetupScreen();
  151. OpenFinestra_di_lavoroWindow();
  152.  
  153. RastPort=Finestra_di_lavoroWnd->RPort; /* prelievo indirizzo della RastPort */
  154.  
  155. /*
  156.  /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  157. (    Rendering primitive grafiche                                            )
  158.  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  159. */
  160.  
  161. /*
  162. Generiamo una sequenza di punti
  163. */
  164. for(cont=0;cont<25;++cont) WritePixel(RastPort,15+cont,15+cont);
  165.  
  166. /*
  167. Generiamo ora una linea orizzontale lunga 125 pixel
  168. */
  169. Move(RastPort, 50,10);
  170. Draw(RastPort, 175,10);
  171.  
  172. /*
  173. Generiamo un'elisse
  174. */
  175. DrawEllipse(RastPort,200,200,85,30);
  176.  
  177. /*
  178. Generiamo quattro cerchi ognuno con un diverso colore
  179. */
  180. for(cont=0;cont<=3;++cont)
  181.    {
  182.     SetAPen(RastPort,cont);
  183.     DrawCircle(RastPort,100+cont*10,100+cont*10,55);
  184.    }
  185.  
  186. /*
  187. Aspettiamo 4 secondi...
  188. */
  189. Delay(200);
  190.  
  191. /*
  192. ...e usciamo dal programma
  193. */
  194. fine();
  195.  
  196. }
  197.  
  198.  
  199. /*
  200.  
  201.  /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  202. (                                  Funzioni                                  )
  203.  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  204.  
  205. */
  206.  
  207. void fine(void)
  208. {
  209. if (GfxBase)        CloseLibrary((struct Library *)GfxBase);
  210. if (IntuitionBase)  CloseLibrary((struct Library *)IntuitionBase);
  211.  
  212. CloseFinestra_di_lavoroWindow();
  213. CloseDownScreen();
  214.  
  215. exit(NULL);
  216. }
  217.